import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
import { getType } from "../api/type";
export const getListAsync = createAsyncThunk('type/getListAsync', async () => {
  const response = await getType()
  return response.data
})

export const typeSlice = createSlice({
  name: 'type',
  initialState: {
    typeList: [],
    issueTypeId: 'all',
    bookTypeId: 'all'
  },
  reducers: {
    updateIssueTypeId(state, { payload }) {
      state.issueTypeId = payload
    }
  },
  extraReducers(builder) {
    builder.addCase(getListAsync.fulfilled, (state, { payload }) => {
      state.typeList = payload
    })
  }
})
export const {updateIssueTypeId} = typeSlice.actions;
export default typeSlice.reducer